<template>
	<view>
		<!-- 1 用户 2商家 -->
		<view v-if="newstatue ==1">
			<messageindex></messageindex>
		</view>
		<view v-if="newstatue ==2">
			<order @changeIndex='changeIndex' :OrderList='OrderList'></order>
		</view>
	</view>
</template>

<script>
	import messageindex from '@/components/messageindex/messageindex.vue'
	import order from '../../pages/order/order.vue'
	export default {
		components: {
			messageindex,
			order
		},
		data() {
			return {
				identity: '',
				newstatue: uni.getStorageSync('newstatue') ? uni.getStorageSync('newstatue') : '1',
				OrderList: {},
				loadstatus: 'more',
				isRefresh: 0,
				page: 1,
				id:0
			}
		},
		onLoad() {
			// if (uni.getStorageSync('shop_id') == '') {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请在首页选择店铺再查看'
			// 	})
			// 	return
			// } else {
			// 	this.shopOrder()
			// }
			this.page = 1;
			this.isRefresh = 1;
			this.shopOrder(this.id)
			this.getUserInfo()
			this.newstatue = uni.getStorageSync('newstatue') ? uni.getStorageSync('newstatue') : '1'
		},
		onShow() {
			// if (uni.getStorageSync('shop_id') == '') {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请在首页选择店铺再查看'
			// 	})
			// 	return
			// } else {
			// 	this.shopOrder()
			// }

			this.newstatue = uni.getStorageSync('newstatue') ? uni.getStorageSync('newstatue') : '1'
		},
		onPullDownRefresh() {
			this.isRefresh = 1;
			this.loadstatus = 'more';
			this.page = 1;
			this.shopOrder(this.id)
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.loadstatus !== 'more') {
				return;
			}
			this.loadstatus = '加载中...';
			this.isRefresh = 0;
			this.shopOrder(this.id)
		},
		methods: {
			//全部的订单数据
			shopOrder(id) {
				this.$Api.shopOrderList({
					shopId: uni.getStorageSync('Bshop_id'),
					status: id,
					page: this.page,
					pageNum: 15,
				}).then(res => {
					// this.OrderList = res.data.data.list
					// console.log(res.data.data, '我是列表')
					if (res.data.data.list.length > 0) {
						if (this.isRefresh) {
							this.OrderList = res.data.data.list;
						} else {
							this.OrderList = this.OrderList.concat(res.data.data.list);
						}
						if (res.data.data.list.length != 15) {
							this.loadstatus = '到底了...';
						} else {
							this.loadstatus = 'more';
							this.page++;
						}
					} else {
						this.loadstatus = '到底了...';
					}
				}).catch(res => {})
			},
			getUserInfo() {
				//获取用户信息
				this.$Api.getUserInfo({
					userId: uni.getStorageSync('userid'),
				}).then(res => {
					this.UserInfo = res.data.data
					this.identity = res.data.data.f_is_c
					console.log(res.data.data, '成功')
				}, err => {})
			},
			changeIndex(id){
				this.id = id	
				this.isRefresh= 0
				this.page= 1
				this.OrderList = []
				this.shopOrder(id)
			}
		},
		mounted() {

		}
	}
</script>

<style lang="scss">

</style>
